//
//  Extension+UIBarButtonItem.swift
//  三期微博1
//
//  Created by TownFish on 16/7/21.
//  Copyright © 2016年 TownFish. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //遍历构造函数
    convenience init(title: String? = nil,imgName:String? = nil,target: AnyObject?, action: Selector) {
        self.init()
        //创建一个button
        let button = UIButton()
        //判断是title还是img
        if let tit = title {
            button.setTitle(tit, forState: UIControlState.Normal)
            button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(15)
            
        }
        if let img = imgName {
            button.setImage(UIImage(named: img), forState: UIControlState.Normal)
        }
        //给button添加点击事件
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        button.sizeToFit()
        self.customView = button
    }
}